package cn.edu.nit.security.handle;

import cn.edu.nit.common.exception.SysBaseError;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
import org.springframework.stereotype.Component;

/**
 * @Author xiaobai
 * @Date 2022/8/22 19:23
 * @Version 1.0.0
 */
@Component
public class AuthenticationFailureHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {

    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
        if (event instanceof AuthenticationFailureBadCredentialsEvent) {
            throw new SysBaseError("账号或密码错误", 300);
        }
    }
}
